//
//  MineLastTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/10.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MineLastTableViewCell.h"
#import "MineSecondCollectionViewCell.h"

#import "PayManageViewController.h"
#import "PasswordManageViewController.h"
#import "ShippingAddressViewController.h"
#import "FinancialRecordViewController.h"
#import "FlowCurrencyController.h"
#import "FrequentlyQuestionViewController.h"
#import "IntegralRecordViewController.h"
#import "OrderMarryController.h"
#import "MineCollectController.h"

static NSString *lastCellID = @"lastCellID";

@interface MineLastTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) UICollectionView *collectionView;

@end


@implementation MineLastTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.collectionView];
    }
    
    return self;
    
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(86));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(86));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(Margin);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-Margin);
        
    }];
}

#pragma mark -delegate\datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.lastArr.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    MineSecondCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:lastCellID forIndexPath:indexPath];
    
    cell.dict = self.lastArr[indexPath.item];
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

//    NSLog(@"最后一组cell点击");
    
    if (![[CommonAction sharedInstance] isLoginWithParentVc:self.parentVC]) {
        
        return;
    }
    
    UIViewController *vc = nil;
    
//    if (indexPath.item == 0) {
//
//        NSLog(@"积分明细");
//        IntegralRecordViewController *integralVC = [[IntegralRecordViewController alloc] init];
//        vc = integralVC;
//
//    }else if (indexPath.item == 1) {
//
//        FlowCurrencyController *flowcCtr = [[FlowCurrencyController alloc] init];
//        vc = flowcCtr;
//
//    }else
        if (indexPath.item == 0) {
        
        NSLog(@"财务记录");
        FinancialRecordViewController *finacialRecordVC = [[FinancialRecordViewController alloc] init];
        finacialRecordVC.type = 0;
        vc = finacialRecordVC;

    }else if (indexPath.item == 1) {
        
        NSLog(@"支付管理");
        PayManageViewController *payManageVC = [[PayManageViewController alloc] init];
        vc = payManageVC;

    }else if (indexPath.item == 2) {
        
        NSLog(@"密码管理");
        
        PasswordManageViewController *passwordManageVC = [[PasswordManageViewController alloc] init];
        vc = passwordManageVC;

    }else if (indexPath.item == 3) {
        
        NSLog(@"我的地址");
        ShippingAddressViewController *addressVC = [[ShippingAddressViewController alloc] init];
        
        vc = addressVC;

    }else if (indexPath.item == 4) {
       
        NSLog(@"常见问题");
        
        FrequentlyQuestionViewController *questionVC = [[FrequentlyQuestionViewController alloc] init];
        vc = questionVC;

    }else if (indexPath.item == 5) {
        
        NSLog(@"订单匹配");
        OrderMarryController *orderVc = [[OrderMarryController alloc] init];
        vc = orderVc;
    }else if (indexPath.item == 6) {
        NSLog(@"我的收藏");
        MineCollectController *collectCtr = [[MineCollectController alloc] init];
        vc = collectCtr;
    } else {
        
    }
    
    [self.parentVC.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark -lazy
- (UICollectionView *)collectionView {
    
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(jisuan(80), jisuan(108));
        flowLayout.minimumLineSpacing = jisuan(40);
        flowLayout.minimumInteritemSpacing = (WIDTH - jisuan(86) * 2 - jisuan(80) * 4) / 3.0;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = WhiteColor;
        
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        
        [_collectionView registerClass:[MineSecondCollectionViewCell class] forCellWithReuseIdentifier:lastCellID];
        
        
        if (@available(iOS 11.0 , *)) {
            
            _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
    }
    
    return _collectionView;
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
